// 地址相关接口
import service from "./index";
const prefix = "/address";

// 新增地址
export function addAddress(addForm) {
  return service({
    url: `${prefix}/addAddress`,
    method: "POST",
    data: addForm,
  });
}

// 修改地址
export function update(updateForm) {
  return service({
    url: `${prefix}/update`,
    method: "PUT",
    data: updateForm,
  });
}

// 分页请求
export function pageList(pageInfo, address) {
  const params = {};
  if (pageInfo == null) {
    params.pageNum = pageInfo.pageNum;
    params.pageSize = pageInfo.pageSize;
  }
  if (address == null) {
    params.id = address.id;
    params.userId = address.userId;
    params.name = address.name;
    params.phone = address.phone;
    params.province = address.province;
    params.city = address.city;
    params.area = address.area;
    params.specific = address.specific;
  }
  return service({
    url: `${prefix}/update`,
    method: "PUT",
    params: params,
  });
}

// 查询本人所有地址
export function list() {
  return service({
    url: `${prefix}/list`,
    method: "GET",
  });
}

// 根据收货地址id删除本人的收货地址
export function deleteById(id) {
  return service({
    url: `${prefix}/delete/${id}`,
    method: "DELETE",
  });
}

// 清空自己的收货地址
export function deleteAll() {
  return service({
    url: `${prefix}/deleteAll`,
    method: "DELETE",
  });
}

// 根据地址id查询地址信息
export function getById(id) {
  return service({
    url: `${prefix}/getById/${id}`,
    method: "GET",
  });
}
